<extend name="Public:base"/>
<block name="title"> 武汉同兴一站办企业服务有限公司 管理中心 - 添加配置 </block>

<block name="header">
    <span class="action-span"><a href="#">添加配置</a></span>
    <span class="action-span1"><a href="{:U('/index.php/Admin')}">武汉同兴一站办企业服务有限公司 管理中心</a></span>
    <span id="search_id" class="action-span1"> - 添加配置 </span>
    <div style="clear:both"></div>
</block>
<block name="body">

    <div class="tab-div">
    <div id="tabbar-div">
        <p>
            <span class="tab-front" id="general-tab">通用信息</span>
          <!--  <span class="tab-front" id="general-tab">商品属性</span>-->
         <!--   <span class="tab-front" id="general-tab">商品相册</span>
            <span class="tab-front" id="general-tab">商品规格</span>-->

        </p>
    </div>
    <div id="tabbody-div">
        <form enctype="multipart/form-data" action="" id="my_form" method="post">

            <table width="90%" class="table"  id="general-table" align="center" >


                <tbody id="sx_name">
                <tr>
                    <td class="label">配置名:</td>
                    <td>
                        <div><input style="width: 200px" type="text"  name="configure_name" value="" /></div>
                        <div style="margin-top: 5px;">
                            <b>配置值: </b><input type="text"  name="configure_value[]" id="testInput" value=""  style="width: 130px;"/>
                             <input type="button" value="+" onclick="jia2box(this)">
                        </div>
                    </td>
                </tr>
                </tbody>

               <!-- <tr>
                    <td class="label">地区:</td>
                    <td>
                        <input type="text" autofocus=""  name="title" id="testInput" size='27' /> <font color="red">购买(地区)配置专用，地区配置不填配置值</font>
                    </td>
                </tr>-->


                <tr>
                    <td class="label">配置售卖地区:</td>
                    <td>
                        <div><input style="width: 200px" type="text"  name="configure_name" value="" /></div> <font color="red">如果配置地区，请填详细地区名(如：武汉市，上海市,江汉区，江岸区...)</font>
                        <div style="margin-top: 5px;">
                            <b>地区名: </b><input type="text"  name="title[]" id="testInput" value=""  style="width: 130px;"/>
                            <input type="button" value="+" onclick="jia2boxs(this)">
                        </div>
                    </td>
                </tr>


                <tr>
                    <td class="label">备注:</td>
                    <td>
                        <input type='text' name='memo' maxlength="20" value='' size='27' />
                    </td>
                </tr>

            </table>




            <div class="button-div">
                <input type="button" id="submit" value=" 确定 " class="button"/>
                <input type="reset" value=" 重置 " class="button" />
            </div>
        </form>
    </div>
</div>

    <script type="text/javascript" src="/public/Admin/JS/jquery.min.js"></script>
    <script>

        $('#submit').click(function (){
            data = $('#my_form').serialize();

            $.ajax({
                url:"{:U('WebConfig/config_add')}",
                type:'post',
                data:data,
                success:function(data){
                    $data = JSON.parse(data);
                    console.log($data);

                    if($data.state == 200){
                        alert($data.rel);
                        window.setTimeout("window.location='{:U('WebConfig/config_list')}'",1000);
                    }

                }
            });
        });

      function jia2box(that){
          $(that).parent().parent().append('<div style="margin-top: 5px;">' +
                  ' <b>配置值: </b><input type="text"  name="configure_value[]"  value=""  style="width: 130px;"/>' +
                  '<input type="button" value="-" onclick="jian2box(this)"></div>');
      }

      function jian2box(that){
          $(that).parent().remove();
      }


        function jia2boxs(that){
            $(that).parent().parent().append('<div style="margin-top: 5px;">' +
                    ' <b>地区名: </b><input type="text"  name="title[]" id="testInput" value=""  style="width: 130px;"/>' +
                    '<input type="button" value="-" onclick="jian2boxs(this)"></div>');
        }

        function jian2boxs(that){
            $(that).parent().remove();
        }
    </script>

    <script>

        var datas = {$city};
        console.log(datas);
        /**
         * 搜索下拉列表
         **/
        $('#testInput').bind('input propertychange',
                function() {
                    var items = inputChange();//搜索数据并获取搜索结果
                    if(items != undefined){
                        _initItems(items);
                    }

                });


        //1：搜索数据
        var inputChange = function() {
            var inputValue = $('#testInput').val();

            if(inputValue != "" && inputValue.indexOf("000") == -1){
                var matcher = new RegExp(inputValue, "i");
                return $.grep(datas,
                        function(value) {
                            return matcher.test(value.name);
                        });
            }else if(inputValue != "" && inputValue.indexOf("000") != -1){
                var matcher = new RegExp(inputValue, "i");
                return $.grep(datas,
                        function(value) {
                            return matcher.test(value.code);
                        });
            }

        };
        var maxFontNumber = 0;//最大字数
        var suggestContainer = $('<div></div>'); //创建一个子<div>
        suggestContainer.attr('id', "testInput-suggest");
        suggestContainer.attr('tabindex', '0');
        suggestContainer.hide();

        //2：初始化搜索到的数据进行显示
        var _initItems = function(items) {
            $('#ruleOrgCode').val("");
            suggestContainer.empty();
            for (var i = 0; i < items.length; i++) {
                if(items[i].name.length > maxFontNumber){
                    maxFontNumber = items[i].name.length;
                }
                var suggestItem = $('<div></div>'); //创建一个子<div>
                suggestItem.attr('code', items[i].code);
                suggestItem.append(items[i].name);
                suggestItem.css({
                    'padding':'3px',//item间距
                    'white-space':'nowrap',
                    'cursor': 'pointer',
                    'background-color': 'RGB(199,237,204)',//默认背景颜色
                    'color': '#000000'//默认字体颜色
                });
                suggestItem.bind("mouseover",
                        function() {
                            $(this).css({
                                'background-color': '#C9302C',//选中背景颜色
                                'color': '#ffffff'//选中字体颜色
                            });
                        });
                suggestItem.bind("mouseout",
                        function() {
                            $(this).css({
                                'background-color': 'RGB(199,237,204)',//默认背景颜色
                                'color': '#000000'//默认字体颜色
                            });
                        });

                suggestItem.bind("click", showClickTextFunction);//选中后处理数据
                //suggestItem.bind("click", itemSelectFunction);
                suggestItem.appendTo(suggestContainer);
                suggestContainer.appendTo(document.body);
            }
            suggestContainer.removeAttr("style");
            suggestContainer.css({
                'border': '1px solid #ccc',
                'max-height': '200px',
                'top': $('#testInput').offset().top + $('#testInput').outerHeight(),
                'left': $('#testInput').offset().left,
                'width': 12*maxFontNumber + 2 * 3 + 30,
                'position': 'absolute',
                'font-size': '12px' ,//默认字体大小
                'font-family':'Arial',
                'z-index': 99999,
                'background-color': '#FFFFFF',
                'overflow-y': 'auto',
                'overflow-x': 'hidden',
                'white-space':'nowrap'

            });
            maxFontNumber = 0;
            suggestContainer.show();
        };

        //3.选中后处理数据
        var showClickTextFunction = function() {
            //alert(this.innerText + "---" + this.getAttribute("code"));
            $('#testInput').val(this.innerText);
            // $('#ruleOrgCode').val(this.getAttribute("code"));
            suggestContainer.hide();
        };

    </script>
</block>

